//
//  ShareTableViewCell.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/4.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

protocol ShareTableViewCellDelegate:NSObjectProtocol {
    func shareToWX(cell:UITableViewCell)
}

class ShareTableViewCell: UITableViewCell {
    var indextLabel:UILabel = UILabel()
    var leftImage:UIImageView = UIImageView()
    var nameLabel:UILabel = UILabel()
    var titleLabel:UILabel = UILabel()
    var numberLable:UILabel = UILabel()
    var priceLable:UILabel = UILabel()
    var freeBtn:UIButton = UIButton()
    var lineView:UIView = UIView()
    
    var delegate:ShareTableViewCellDelegate?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUI()
    }
    
    
    func setUI() {
        indextLabel.font = Font_Medium(20)
        indextLabel.textAlignment = .center
        indextLabel.textColor = RGB_Same(0)
        contentView.addSubview(indextLabel)
        
        leftImage.layer.cornerRadius = 3
        leftImage.layer.masksToBounds = true
        contentView.addSubview(leftImage)
        
        nameLabel.font = Font_Medium(17)
        nameLabel.textAlignment = .left
        nameLabel.textColor = RGB_Same(0)
        contentView.addSubview(nameLabel)
        
        titleLabel.font = Font_Medium(14)
        titleLabel.textAlignment = .left
        titleLabel.textColor = RGB_Same(53)
        contentView.addSubview(titleLabel)
        
        numberLable.font = Font_Regular(14)
        numberLable.textAlignment = .left
        numberLable.textColor = RGB_Same(53)
        contentView.addSubview(numberLable)
        
        priceLable.font = Font_Medium(14)
        priceLable.textColor = RGB(230, 67, 64)
        priceLable.textAlignment = .right
        contentView.addSubview(priceLable)
        
        freeBtn = UIButton(type: UIButton.ButtonType.custom)
        freeBtn.setTitle("免费听", for: .normal)
        freeBtn.setTitleColor(.white, for: .normal)
        freeBtn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
        freeBtn.layer.cornerRadius = 4
        freeBtn.addTarget(self, action: #selector(freeBtnAction), for: .touchUpInside)
        freeBtn.backgroundColor = RGB(255, 151, 29)
        contentView.addSubview(freeBtn)
        
        lineView.backgroundColor = RGB_Same(240, 1)
        contentView.addSubview(lineView)

        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    @objc func freeBtnAction() {
        delegate?.shareToWX(cell: self)
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override func layoutSubviews() {
        indextLabel.frame = FRAME_CGFloat(0, 38, 32, 28)
        leftImage.frame = FRAME_CGFloat(32, 10, 84, 84)
        nameLabel.frame = FRAME_CGFloat(126, 10, SCREEN_WIDTH - 200, 24)
        titleLabel.frame = FRAME_CGFloat(126, 37.5, SCREEN_WIDTH - 140, 20)
        numberLable.frame = FRAME_CGFloat(126, 65, SCREEN_WIDTH - 250, 20)
        priceLable.frame = FRAME_CGFloat(SCREEN_WIDTH - 100, 13, 83.5, 24)
        freeBtn.frame = FRAME_CGFloat(SCREEN_WIDTH - 89, 66, 79, 28)
        lineView.frame = FRAME_CGFloat(0, 103, SCREEN_WIDTH, 1)
    }

}
